package com.eastfair.common.service.impl;

import cn.hutool.core.date.StopWatch;
import com.eastfair.common.dto.GmApiHostInfDtos;
import com.eastfair.common.res.CrmResult;
import com.eastfair.common.service.CommonInterfaceCallRecordService;
import com.eastfair.common.service.CrmHostSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * CRM 主办 service.
 *
 * @author dqq
 * @date 2023 /2/13
 */
@Service
@Slf4j
public class CrmHostSyncServiceImpl implements CrmHostSyncService {

    @Value("${roma.ipport}")
    private String romaIpport;

    @Value("${roma.CRM-X-HW-ID}")
    private String romaXHWID;

    @Value("${roma.CRM-X-HW-APPKEY}")
    private String romaXHWAPPKEY;

    @Value("${crm.sponsor.url}")
    private String crmSponsorUrl;

    @Resource
    private CommonInterfaceCallRecordService commonInterfaceCallRecordService;

    @Override
    public CrmResult syncHostInfo(GmApiHostInfDtos gmApiHostInfDtos) {
        log.info("syncHostInfo - 同步主办, gmApiHostInfDtos={}", gmApiHostInfDtos);
        String httpUrl = romaIpport + crmSponsorUrl;
        StopWatch sw = new StopWatch();
        sw.start("syncHostInfo");
        String result = commonInterfaceCallRecordService.processHttp(httpUrl, gmApiHostInfDtos, romaXHWID, romaXHWAPPKEY);
        log.info("syncHostInfo - 同步主办结果, result={}", result);
        sw.stop();
        log.info(sw.getLastTaskName(), sw.getTotalTimeMillis());
        return null;
    }
}